
const state = {
    userInformation: {},
    userCollect: {},
    userMastery: {},
    userVip: {},
    userVipList: [
        {'name':'畅聊套餐','vipTypeCode':1},
        {'name':'认知套餐','vipTypeCode':2},
        {'name':'成长套餐','vipTypeCode':3},
    ],
    userRouter: '',
    userFreeEntery: false,
}
const getters = {
    //获取用户登录信息
    getUserInformation(state) {
        return state.userInformation
    },
    //获取用户收集的信息
    getUserCollect(state) {
        return state.userCollect
    },
    //用户评测结果
    getUserMastery(state) {
        return state.userMastery
    },
    //获取用户的vip相关数据
    getUserVip(state){
        return state.userVip
    },
    //获取用户开通vip的信息
    getUserVipList(state){
        return state.userVipList
    },
    //获取用户路径
    getUserRouter(state){
        return state.userRouter
    },
};
const mutations = {
    //设置用户登录信息
    setUserInformation(state, param) {
        if (!param.detail) {
            param.detail = {
                nickname: "",
                gender: 0,
                age: 0
            }
        }
        state.userInformation = param
    },
    //初始化评测结果
    setUserMastery(state, param) {
        state.userMastery = param
    },
    //设置用户评测详情
    studyExplain(state, param) {
        state.userMastery.studyExplain = param
    },
    //设置用户收集的信息
    setUserCollect(state, param) {
        state.userCollect = param
    },
    //新增意象收集
    insertImageryCollect(state, param) {
        const list = state.userCollect.imagery.filter(item => { return item.eryId === param.eryId })
        if (list.length === 0) state.userCollect.imagery.push(param)
    },
    //新增角色收集
    insertRoleCollect(state, param) {
        const list = state.userCollect.role.filter(item => { return item.explain.replace(/\d+$/, '') === param.explain.replace(/\d+$/, '') })
        if (list.length === 0) state.userCollect.role.push(param)
    },
    //设置用户手机号
    setUserPhoneNumber(state, param) {
        state.userInformation.phoneNumber = param
    },
    //用户微信绑定
    updateWeixinBound(state, param) {
        state.userInformation.isWechat = true
    },
    //设置用户个人信息
    setUserDetail(state, param) {
        state.userInformation.detail = param
    },
    //设置用户vip相关数据
    setUserVip(state,param){
        state.userVip = param
    },
    //设置用户vip开通信息
    setUserVipList(state,param){
        state.userVipList = param
    },
    //设置用户路径
    setUserRouter(state,param){
        state.userRouter = param
    },
    //设置用户进入方式
    setUserFreeEntery(state,param){
        state.userVip.userFreeEntery = param
    }
};
const actions = {
    setUserInformation({ commit }, param) {
        commit("setUserInformation", param)
    },
    setUserCollect({ commit }, param) {
        commit("setUserCollect", param)
    },
    insertImageryCollect({ commit }, param) {
        commit("insertImageryCollect", param)
    },
    insertRoleCollect({ commit }, param) {
        commit("insertRoleCollect", param)
    },
    setUserPhoneNumber({ commit }, param) {
        commit("setUserPhoneNumber", param)
    },
    setUserDetail({ commit }, param) {
        commit("setUserDetail", param)
    },
    setUserMastery({ commit }, param) {
        commit("setUserMastery", param)
    },
    updateWeixinBound({ commit }, param) {
        commit("updateWeixinBound", param)
    },
    studyExplain({ commit }, param) {
        commit("studyExplain", param)
    },
    setUserVip({ commit }, param) {
        commit("setUserVip", param)
    },
    setUserVipList({ commit }, param) {
        commit("setUserVipList", param)
    },
    setUserRouter({ commit }, param) {
        commit("setUserRouter", param)
    },
    setUserFreeEntery({ commit }, param) {
        commit("setUserFreeEntery", param)
    },
};
export default {
    namespaced: true,//用于在全局引用此文件里的方法时标识这一个的文件名
    state,
    getters,
    mutations,
    actions
}
